package top.hmtools;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

import javafx.stage.Stage;

@Component
public class GMContext implements ApplicationContextAware{
	
	private final Logger logger = LoggerFactory.getLogger(this.getClass());
	public static ApplicationContext applicationContext;
	public static Stage primaryStage;

	/**
	 * 启动时执行 
	 */
	@PostConstruct
	public void init(){
		logger.info("项目启动初始化开始。。。");
		logger.info("项目启动初始化结束。。。");
	}
	
	/**
	 * 销毁前执行
	 */
	@PreDestroy
	public void doBeforeDestory(){
		logger.info("销毁前执行开始。。。");
		logger.info("销毁前执行结束。。。");
	}

	@Override
	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
		GMContext.applicationContext = applicationContext;
	}

	/**
	 * 设置主窗口
	 * @param stage
	 */
	public static void setPrimaryStage(Stage stage) {
		GMContext.primaryStage=stage;
	}
	
	/**
	 * 获取主窗口
	 * @return
	 */
	public static Stage getPrimaryStage(){
		return GMContext.primaryStage;
	}
}
